package com.eleadmin.order.controller;

import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.order.entity.ContainerBillFee;
import com.eleadmin.order.service.ContainerBillFeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 订单运费
 * @author : Doman
 * @date : 2023-03-24 15:37:47
 * @version ：1.0
 */

@Api(tags = "订单运费")
@RestController
@RequestMapping("/api/order/containerBillFee")
public class ContainerBillFeeController extends BaseController {

    @Autowired
    private ContainerBillFeeService containerBillFeeService;

    @PreAuthorize("hasAuthority('order:containerBillFee:list')")
    @ApiOperation("分页查询订单运费")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, ContainerBillFee containerBillFee) throws Exception{
        return containerBillFeeService.list(page, containerBillFee, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:containerBillFee:list')")
    @ApiOperation("查询全部订单运费")
    @GetMapping()
    public JsonResult list(ContainerBillFee containerBillFee){
        return containerBillFeeService.list(containerBillFee, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:containerBillFee:list')")
    @ApiOperation("根据id查询订单运费")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return containerBillFeeService.getById(id);
    }


    @PreAuthorize("hasAuthority('order:containerBillFee:save')")
    @OperationLog
    @ApiOperation(value ="添加订单运费")
    @PostMapping()
    public JsonResult save(@RequestBody ContainerBillFee containerBillFee) {
        try {
            return containerBillFeeService.save(containerBillFee, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('order:containerBillFee:update')")
    @OperationLog
    @ApiOperation(value ="修改订单运费")
    @PutMapping()
    public JsonResult update(@RequestBody ContainerBillFee containerBillFee) {
        try {
            return containerBillFeeService.update(containerBillFee, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:containerBillFee:remove')")
    @OperationLog
    @ApiOperation(value ="删除订单运费")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return containerBillFeeService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
